/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Ultrasonic;
/**
 *
 * @author Eric
 */
public class SonarSensor {
    static int distancetrack=0;
    static int echochan,pingchan;
    
    static Ultrasonic sonar;
    
        
    public SonarSensor(int channel1,int channel2)
    {
        echochan=channel1;
        pingchan=channel2;
    }
    
    public void initSonar()
    {
        sonar = new Ultrasonic(echochan,pingchan);
        sonar.setEnabled(true);
        sonar.setAutomaticMode(true);
        
    }
    
    public double getDistance()
    {
        if (sonar.isRangeValid())
        {
            return sonar.getRangeInches();
        }
        else
        {
            return 0;
        }
    }
    
    void disableSonar()
    {
        sonar.setEnabled(false);
    }
    
}
